using HKB.Common;
using System;
using System.Data;
using System.Text;
using System.Web;
namespace HKB.Web
{
	public class Shop_Application
	{
		private Conn conn = null;
		private static Shop_Application _instance = null;
		private Pagination _pageHand = null;
		public static Shop_Application instance
		{
			get
			{
				if (Shop_Application._instance == null)
				{
					Shop_Application._instance = new Shop_Application(new Conn());
				}
				return Shop_Application._instance;
			}
		}
		protected Pagination pageHand
		{
			get
			{
				Pagination pageHand;
				if (this._pageHand == null)
				{
					this._pageHand = new Pagination();
					this._pageHand.SQL_CloseTablePre = false;
					this._pageHand.P_Object = Language.Get("Ventify/Name");
					pageHand = this._pageHand;
				}
				else
				{
					pageHand = this._pageHand;
				}
				return pageHand;
			}
		}
		public Shop_Application(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_Application()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
			if (this.conn == null)
			{
				this.conn = new Conn();
			}
		}
		public DataTable GetAllApplication(int indexpage, int maxperpage, string wherestr, string orderbystr)
		{
			return this.pageHand.GetDataTable("HLShop_Application", indexpage, maxperpage, "IdentifyID", wherestr, orderbystr, this.conn, null);
		}
		public string GetPagePanel(string linkHead)
		{
			this.pageHand.P_LinkHead = linkHead;
			return this.pageHand.ShowPagePanel();
		}
		public DataTable GetApplicationByIdentifyID(int IdentifyID)
		{
			DataTable result;
			if (IdentifyID > 0)
			{
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@IdentifyID", DbType.Int32, IdentifyID);
				result = this.conn.GetDataTable("SELECT * FROM [HLShop_Application] WHERE IdentifyID=@IdentifyID", new IDbDataParameter[]
				{
					dbDataParameter
				});
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetApplicationTimeStatusByUserID(int UserID)
		{
			DataTable result;
			if (UserID > 0)
			{
				IDbDataParameter dbDataParameter = this.conn.CreateParameter("@UserID", DbType.Int32, UserID);
				result = this.conn.GetDataTable("SELECT * FROM HLShop_Application WHERE UserID=@UserID", new IDbDataParameter[]
				{
					dbDataParameter
				});
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetApplicationByUserIDType(int UserID, int IdentifyType)
		{
			DataTable result;
			if (UserID > 0 && IdentifyType >= 0)
			{
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
					this.conn.CreateParameter("@IdentifyType", DbType.String, IdentifyType)
				};
				result = this.conn.GetDataTable("SELECT * FROM HLShop_Application WHERE UserID=@UserID AND IdentifyType=@IdentifyType", parameters);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public bool AddApplication(int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl)
		{
			return this.AddApplication(UserID, UserName, IdentifyType, IdentifyDetail, Remark, UploadPhotoUrl, "", 9);
		}
		public bool AddApplication(int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl, string Editor, int Status)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@IdentifyType", DbType.Int32, IdentifyType),
				this.conn.CreateParameter("@IdentifyDetail", DbType.String, IdentifyDetail),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@UploadPhotoUrl", DbType.String, UploadPhotoUrl),
				this.conn.CreateParameter("@Editor", DbType.String, Editor),
				this.conn.CreateParameter("@Status", DbType.Int32, Status)
			};
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				this.conn.ExecuteTransaction("Insert Into HLShop_Application(UserID,UserName,IdentifyType,Status,AplayTime,Editor,Remark,UploadPhotoUrl,IdentifyDetail) values(@UserID,@UserName,@IdentifyType,@Status,'" + DateTime.Now + "',@Editor,@Remark,@UploadPhotoUrl,@IdentifyDetail)", parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=",
					Status,
					" Where UserID=",
					UserID
				}));
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public bool AddApplication(int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl, string sqlUser, string sqlUserInfo)
		{
			return this.AddApplication(UserID, UserName, IdentifyType, IdentifyDetail, Remark, UploadPhotoUrl, "", 9, sqlUser, sqlUserInfo);
		}
		public bool AddApplication(int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl, string Editor, int Status, string sqlUser, string sqlUserInfo)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@IdentifyType", DbType.Int32, IdentifyType),
				this.conn.CreateParameter("@IdentifyDetail", DbType.String, IdentifyDetail),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@UploadPhotoUrl", DbType.String, UploadPhotoUrl),
				this.conn.CreateParameter("@Editor", DbType.String, Editor),
				this.conn.CreateParameter("@Status", DbType.Int32, Status)
			};
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				this.conn.ExecuteTransaction("Insert Into HLShop_Application(UserID,UserName,IdentifyType,Status,AplayTime,Editor,Remark,UploadPhotoUrl,IdentifyDetail) values(@UserID,@UserName,@IdentifyType,@Status,'" + DateTime.Now + "',@Editor,@Remark,@UploadPhotoUrl,@IdentifyDetail)", parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=9 Where UserID=",
					UserID
				}));
				this.conn.ExecuteTransaction(sqlUser);
				this.conn.ExecuteTransaction(sqlUserInfo);
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public bool ModifyApplication(int IdentifyID, int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@IdentifyDetail", DbType.String, IdentifyDetail),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@UploadPhotoUrl", DbType.String, UploadPhotoUrl)
			};
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				string commandText = string.Concat(new object[]
				{
					"Update HLShop_Application Set UserID = @UserID, UserName = @UserName, Status = 9, AplayTime='",
					DateTime.Now,
					"', Remark =@Remark, UploadPhotoUrl = @UploadPhotoUrl, IdentifyDetail = @IdentifyDetail Where IdentifyID=",
					IdentifyID
				});
				this.conn.ExecuteTransaction(commandText, parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=9 Where UserID=",
					UserID
				}));
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public bool ModifyApplication(int IdentifyID, int UserID, string UserName, int IdentifyType, string IdentifyDetail, string Remark, string UploadPhotoUrl, string sqlUser, string sqlUserInfo)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@IdentifyDetail", DbType.String, IdentifyDetail),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@UploadPhotoUrl", DbType.String, UploadPhotoUrl)
			};
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				string commandText = string.Concat(new object[]
				{
					"Update HLShop_Application Set UserID = @UserID, UserName = @UserName, Status = 9, AplayTime='",
					DateTime.Now,
					"', Remark =@Remark, UploadPhotoUrl = @UploadPhotoUrl, IdentifyDetail = @IdentifyDetail Where IdentifyID=",
					IdentifyID
				});
				this.conn.ExecuteTransaction(commandText, parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=9 Where UserID=",
					UserID
				}));
				this.conn.ExecuteTransaction(sqlUser);
				this.conn.ExecuteTransaction(sqlUserInfo);
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public bool UpdateApplication(int UserID, int IdentifyID, int IdentifyType, string Remark, string Editor, int Status, string UserName, string IdentifyDetail, string UploadPhotoUrl)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@IdentifyType", DbType.Int32, IdentifyType),
				this.conn.CreateParameter("@IdentifyDetail", DbType.String, IdentifyDetail),
				this.conn.CreateParameter("@Remark", DbType.String, Remark),
				this.conn.CreateParameter("@UploadPhotoUrl", DbType.String, UploadPhotoUrl),
				this.conn.CreateParameter("@Editor", DbType.String, Editor),
				this.conn.CreateParameter("@Status", DbType.Int32, Status)
			};
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update HLShop_Application Set Status = @Status, UpdateTime='",
					DateTime.Now,
					"', Remark = @Remark, Editor=@Editor Where IdentifyID=",
					IdentifyID
				}), parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=",
					Status,
					" Where UserID=",
					UserID
				}));
				this.conn.Commit();
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		public bool CheckUpdateApplication(int UserID, int IdentifyID, int IdentifyType, string Remark, string Editor, int Status)
		{
			string commandText = string.Concat(new object[]
			{
				"Update HLShop_Application Set Status =",
				Status,
				", UpdateTime='",
				DateTime.Now,
				"', Remark = '",
				Remark,
				"', Editor='",
				Editor,
				"' Where IdentifyID=",
				IdentifyID
			});
			string text = "";
			switch (IdentifyType)
			{
			case 1:
				text = "AuthenticationType";
				break;
			case 2:
				text = "CompanyIdentify";
				break;
			case 3:
				text = "BandShopIdentify";
				break;
			case 4:
				text = "OtherIdentify2";
				break;
			}
			this.conn.BeginTransaction();
			bool result;
			try
			{
				this.conn.ExecuteTransaction(commandText);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_UserInfo] Set ",
					text,
					"=",
					Status,
					" Where UserID=",
					UserID
				}));
				this.conn.Commit();
			}
			catch
			{
				this.conn.Rollback();
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		public string AddPersonIdentifyDetail(string TrueName, string IDCardNum, string IDCardUploadUrl, string HomePhone, string Mobile)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("TrueName|" + TrueName + "$");
			stringBuilder.Append("IDCardNum|" + IDCardNum + "$");
			stringBuilder.Append("IDCardUploadUrl|" + IDCardUploadUrl + "$");
			stringBuilder.Append("HomePhone|" + HomePhone + "$");
			stringBuilder.Append("Mobile|" + Mobile + "$");
			return stringBuilder.ToString();
		}
		public string AddPersonIdentifyDetail(string TrueName, string IDCardNum, string IDCardUploadUrl, string IDCardUploadUrlBack, string HomePhone, string Mobile)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("TrueName|" + TrueName + "$");
			stringBuilder.Append("IDCardNum|" + IDCardNum + "$");
			stringBuilder.Append("IDCardUploadUrl|" + IDCardUploadUrl + "$");
			stringBuilder.Append("IDCardUploadUrlBack|" + IDCardUploadUrlBack + "$");
			stringBuilder.Append("HomePhone|" + HomePhone + "$");
			stringBuilder.Append("Mobile|" + Mobile + "$");
			return stringBuilder.ToString();
		}
		public string AddCompanyIdentifyDetail(string CompanyName, string CompanylicenseName, string CompanylicenseNum, string ContacterName, string ContacterAddress, string ContacterPhone, string ContacterMobile, string ContacterFax, string CompanyAddress, string CompanyProvince, string CompanyCity, string ContacterIDCardNum, string CompayType, string CompanyRange, string CompanylicenseUpload, string ContacterEmail, string CompanyArea)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("CompanyName|" + CompanyName + "$");
			stringBuilder.Append("CompanylicenseName|" + CompanylicenseName + "$");
			stringBuilder.Append("CompanylicenseNum|" + CompanylicenseNum + "$");
			stringBuilder.Append("CompanylicenseUpload|" + CompanylicenseUpload + "$");
			stringBuilder.Append("CompayType|" + CompayType + "$");
			stringBuilder.Append("CompanyAddress|" + CompanyAddress + "$");
			stringBuilder.Append("CompanyRange|" + CompanyRange + "$");
			stringBuilder.Append("CompanyProvince|" + CompanyProvince + "$");
			stringBuilder.Append("CompanyCity|" + CompanyCity + "$");
			stringBuilder.Append("CompanyAddress|" + CompanyAddress + "$");
			stringBuilder.Append("ContacterName|" + ContacterName + "$");
			stringBuilder.Append("ContacterPhone|" + ContacterPhone + "$");
			stringBuilder.Append("ContacterMobile|" + ContacterMobile + "$");
			stringBuilder.Append("ContacterFax|" + ContacterFax + "$");
			stringBuilder.Append("ContacterIDCardNum|" + ContacterIDCardNum + "$");
			stringBuilder.Append("ContacterEmail|" + ContacterEmail + "$");
			stringBuilder.Append("CompanyArea|" + CompanyArea + "$");
			return stringBuilder.ToString();
		}
		public static string GetContentByName(string TitleName, string[] ContentArray)
		{
			string result;
			if (ContentArray != null && ContentArray.Length > 0)
			{
				for (int i = 0; i < ContentArray.Length; i++)
				{
					string[] array = ContentArray[i].Split(new char[]
					{
						'|'
					});
					if (array[0] == TitleName)
					{
						result = array[1];
						return result;
					}
				}
			}
			result = "";
			return result;
		}
	}
}
